app.controller('BusShiftInsertModalCtrl', function ($scope,$filter, $modalInstance, $modal,$rootScope, toaster, param, ajax) {
	
    $scope.param = param;
    if ($scope.param.data == null) {
        $scope.param.data = {};
    }

    $scope.timeRange={};
    
    ////获取车辆型号配置
    //$scope.loadmodel=function(){
    //    var promise = ajax.call(new Req.GET({
    //        resource: 'vehicle/bs/model/list'
    //    }));
    //    promise.then(function(result) {
    //        $scope.modelList = result.result;
    //    }, function() { });
    //}
    //
    //$scope.loadmodel();
    

    $scope.ok = function () {
		if ($scope.myForm.$valid) {
			//if($scope.modelList.selected == undefined){
             //   toaster.pop('warning', '提示', '请选择车辆型号！');
             //   return;
			//}
			if ($scope.timeRange.startTime ==null|| $scope.timeRange.endTime==null) {
                toaster.pop('warning', '提示', '请选择发班时间！');
                return;
			} 
			if($scope.timeRange.startTime > $scope.timeRange.endTime){
                toaster.pop('warning', '提示', '结束时间不能小于开始时间！');
                return;
			}
			$scope.date=$filter("date")(new Date(), "yyyy-MM-dd");
			$scope.start=$filter("date")($scope.timeRange.startTime, "yyyy-MM-dd");
			if($scope.start<  $scope.date){
                toaster.pop('warning', '提示', '发班开始时间不可小于当天！');
                return;
			}
			$scope.param.data.userId=$rootScope.loginUser.id;
			//$scope.param.data.vehicleModel=$scope.modelList.selected.model;
			$scope.param.data.fromDate = $scope.timeRange.startTime;
			$scope.param.data.toDate =$scope.timeRange.endTime;
			$modalInstance.close($scope.param);
		}
    };

    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };
});